package chars;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/11
 */
public class FileWriterExample {
    public static void main(String[] args) {
        demo();
    }
    private static void demo()
    {
        try(FileWriter f1 = new FileWriter("./io/src/chars/file1.txt");
            FileWriter f2 = new FileWriter("./io/src/chars/file2.txt");
            FileWriter f3 = new FileWriter("./io/src/chars/file3.txt")
        ){
            String source = "1234567890";
            int length = source.length();
            char[] buff = source.toCharArray();

            for(int i=0;i<length;i+=2){
                f1.write(buff[i]);
            }

            f2.write(source);
            //f2.write(buff);//等价

            //写最后四分之一  （写出来的是90，因为7.5就是第8个字节，也就是会从第9个字节开始写）
            f3.write(buff,buff.length-buff.length/4,buff.length/4);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
